#ifndef __PWHDR_IOPOLLPOLL_HPP__
#define __PWHDR_IOPOLLPOLL_HPP__

namespace purewell
{
#if defined(__PW_HAVE_POLL)

#define __PW_POLL_INIT_SIZE (10240)

class PWIOPollPollCont
{
public:
	typedef struct pollfd	poll_t;

public:
	PWIOPollPollCont();
	virtual ~PWIOPollPollCont();

	bool add(int fd, PWFile* pfile, int events);
	bool remove(int fd);
	bool modify(int fd, int events);
	void clear(void);

	inline poll_t* getPolls(void)
	{
		return m_vec;
	}

	inline size_t getCurrentSize(void) const
	{
		return m_cur;
	}

	PWFile* getFile(int fd);
	const PWFile* getFile(int fd) const;

private:
	bool _increase(void);

private:
	typedef struct filedes_t
	{
		PWFile*		pfile;
		size_t		index;

		inline filedes_t(PWFile* pf, size_t i) : pfile(pf), index(i) {}
	} filedes_t;

	typedef std::map<int, filedes_t>	index_cont;
	typedef index_cont::iterator		index_itr;
	typedef index_cont::const_iterator	index_citr;

private:
	index_cont	m_idx;
	poll_t*		m_vec;
	size_t		m_max;
	size_t		m_cur;
};

class PWIOPollPoll : public PWIOPoll
{
public:
	explicit PWIOPollPoll();
	virtual ~PWIOPollPoll();

public:
	virtual bool add(PWFile* pfile, int event);
	virtual bool add(PWPairFile* pfile, size_t idx, int event);
	virtual bool modify(PWFile* pfile, int event);
	virtual bool modify(PWPairFile* pfile, size_t idx, int event);
	virtual bool modify(int fd, int event);
	virtual bool remove(PWFile* pfile);
	virtual bool remove(PWPairFile* pfile, size_t idx);
	virtual bool remove(int fd);
	virtual bool dispatch(int msec);
	virtual const char* getType(void) const;

	virtual bool initialize(void* param);
	virtual void destroy(void);

private:
	PWIOPollPollCont	m_cont;

};
#else
class PWIOPollSelect;
typedef PWIOPollSelect PWIOPollPoll;
#endif//__PW_HAVE_POLL
};//namespace purewell

#endif//!__PWHDR_IOPOLLPOLL_HPP__

